<?php

class Damages_Tags {

  const TAG_TEMPLATE = '[[%s]]';

  static private $_instance = null;

  /**
   *
   * @var Zend_Config_Xml 
   */
  private $tags;

  private function __construct() {
    ;
  }

  /**
   * Class constructor 
   */
  public function init() {
    $config = Damages_Config::getInstance()->tags;
    $filename = Zend_Controller_Front::getInstance()->getModuleDirectory('damages') . $config->fileName;
    if (!file_exists($filename))
      throw new Exception("File: " . $filename . " doesn't exist");
    $this->tags = new Zend_Config_Xml($filename);
  }

  /**
   * 
   * @return Damages_Tags
   */
  public static function getInstance() {
    if (self::$_instance === null) {
      self::$_instance = new self();
      self::$_instance->init();
    }
    return self::$_instance;
  }

  /**
   * getter 
   * 
   * @param string $property - name of config parameter
   * @return string - value of requested parameter
   */
  public final function __get($property) {
    return $this->getTagByCode($property);
  }

  public function getList() {
    return $this->tags->tags->tag;
  }

  public function getTagByCode($code) {
    foreach ($this->tags->tags->tag as $tag) {
      if ($tag->code == $code)
        return $tag;
    }
    return null;
  }

}

?>